/*
 * @Author: wangqizhang
 * @Date: 2024-05-04 14:05:01
 * @LastEditors: wangqizhang
 * @LastEditTime: 2024-05-12 16:45:27
 * @FilePath: /suixinji-server/controller/note.controller.js
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
const {
  findNoteList,
  addNote,
  findNoteByGroupId,
  updateNoteData,
  findDefaultNote,
} = require('../service/note.service');
const { getUrlParams, dealResponse } = require('../until');

class NoteController {
  // 创建笔记
  async createNote(ctx, next) {
    ctx.request.body.user_id = ctx.state.user.id;
    const res = await addNote(ctx.request.body);
    dealResponse(ctx, res);
  }
  async getNoteList(ctx, next) {
    const res = await findNoteList(ctx.state.user.id);
    dealResponse(ctx, res);
  }
  async getNoteDataById(ctx, next) {}
  async getNoteDataByGroupId(ctx, next) {
    const { id } = getUrlParams(ctx.request.url);
    const res = await findNoteByGroupId(id);
    dealResponse(ctx, res);
  }
  async updateNote(ctx, next) {
    const res = await updateNoteData(ctx.request.body);
    dealResponse(ctx, res);
  }
  async getDefaultNote(ctx, next) {
    const userId = ctx.state.user.id;
    const res = await findDefaultNote(userId);
    dealResponse(ctx, res);
  }
}
module.exports = new NoteController();
